<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function getInfo(Request $request)
    {
        $user = User::findOrFail($request->user()->id, ['username', 'avatar']);

        return $user;
    }

    // return user_id
    public function getUserId(Request $request)
    {
        if (empty($username = $request->input('username', ''))) {
            return \App\Org\Developer\JsonReturnInfo::infoEmpty('username');
        }

        $userId = \App\Models\User::where(['username' => $username])->value('id');
        if (isset($userId)) {
            return \App\Org\Developer\JsonReturnInfo::infoSuccess('获取userId成功.', ['user_id' => $userId]);
        }     
    }
}

